package com.junchenrobot.mes.aop;

import com.junchenrobot.mes.response.impl.RcsResponse;
import com.junchenrobot.mes.vo.param.TaskStateParam;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * aop打印任务日志
 *
 * @author SeaWave
 * @date 2023/01/30
 */
@Slf4j
@Aspect
@Component
public class TaskLoggerAOP {
    
    @Pointcut(value = "execution(* com.junchenrobot.mes.controller.RcsController.taskState(..))")
    public void logger() {
    }
    
    /**
     * 打印 请求入参出参
     */
    @Around(value = "logger()")
    public Object aroundController(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        Object[] args = proceedingJoinPoint.getArgs();
        TaskStateParam taskStateParam = (TaskStateParam) args[0];
        String taskNo = taskStateParam.getTaskNo();
        Object proceed = proceedingJoinPoint.proceed();
        RcsResponse rcsResponse = (RcsResponse) proceed;
        log.info("{} state={} : result={}", taskNo, taskStateParam.getState(), rcsResponse.getResult());
        return proceed;
    }
    
    
}
